package com.wdz.currency_query.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.IService;
import com.wdz.currency_query.utils.Param;
import com.wdz.redis.ApplicationContextUtil;
import com.wdz.utils.PageUtil;
import com.wdz.utils.m_lang.StringUtils;


public class CurrencyQueryService {
    private String buildTable_name(String table_name){
        StringBuilder str = new StringBuilder(table_name);
        str.append("ServiceImpl");
        return str.toString();
    }
    public PageUtil searchCurr(String table_name, Param param){
        PageUtil pageUtil = new PageUtil();
        StringUtils stringUtils = StringUtils.getInstance();
        IService iService = (IService) ApplicationContextUtil.getBean(buildTable_name(stringUtils.tran1(table_name)));
        if(param.getKeywords() != null){
            if(param.getPageNo() != null && param.getPageSize() != null){
                Page page = new Page(param.getPageNo(),param.getPageSize());
                pageUtil.setData(iService.selectPage(page,param.getKeywords().getCompareSentence()).getRecords());
            }else {
                pageUtil.setData(iService.selectMaps(param.getKeywords().getCompareSentence()));
            }
        }else if(param.getCompare() != null){
            pageUtil.setData(iService.selectMaps(param.getCompare().getCompareSentence()));
        }
        return pageUtil;
    }
}
